import { getBannerList } from "@/services/banner"
import { IBanner } from './banner'
import { Effect, ImmerReducer } from 'umi'
export interface IBannerState {
  bannerList: IBanner[]
}
export interface IBannerModel {
  namespace: 'banner',
  state: IBannerState,
  effects: {
    getBannerListReq: Effect
  },
  reducers: {
    changeBannerList: ImmerReducer<IBannerState>
  }
}
const bannerModel: IBannerModel = {
  namespace: 'banner',
  state: {
    bannerList: []
  },
  effects: {
    *getBannerListReq ({ payload }: any, { call, put }: any) {
      const res = yield call(getBannerList, payload)
      yield put({
        type: 'changeBannerList',
        payload: res.data.data
      })
    }
  },
  reducers: {
    changeBannerList (state, action) {
      state.bannerList = action.payload
    }
  }
}

export default bannerModel
